package com.pandora.credit.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.pandora.common.util.*;
import com.pandora.credit.dao.TrackDao;
import com.pandora.credit.dto.request.TrackPostRequest;
import com.pandora.credit.entity.Track;
import com.pandora.credit.service.TrackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author developer
 */
@Service
public class TrackServiceImpl implements TrackService {
    @Autowired
    private TrackDao trackDao;

    @Override
    public void save(Track track) {
        trackDao.insert(track);
    }

    @Override
    public Object doPostTrackInfo(String authorizationToken, TrackPostRequest req) {
        String mobile = JedisUtil.get(Constants.BUSINESS_REDIS_URL,
                StringUtils.getStrParam(Constants.AUTHORIZATION_TOKEN_KEY, authorizationToken));
        if(!VerifyUtil.isEmpty(req.getId())){
            String dt = DateUtil.getFormatDateTime();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code", req.getId());
            jsonObject.put("account", mobile);
            jsonObject.put("dt", dt);
            jsonObject.put("terminal_id", req.getTerminalId());
            String key = "queue"+":"+"track";
//            JedisUtil.set(Constants.QUEUE_REDIS_URL,
//                    key,
//                    jsonObject.toString(),
//                    -1);
            JedisUtil.rpush(Constants.QUEUE_REDIS_URL,
                    key,
                    jsonObject.toString());
        }
        return null;
    }

}
